package com.ruoyi.quartz.task;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {
    @Resource
    private ShardTableHandler shardTableHandler;

    public void createTable() {
        System.out.println("定时执行自动建表...");

        // 获取当前年月
        int year = LocalDate.now().getYear();
        int month = LocalDate.now().getMonthValue();
        month = month >= 12 ? 1 : month + 1;
        String monthStr = month >= 10 ? month + "" : "0" + month;

        String tableName_laneApply = ShardTableHandler.TABLE_NAME_PREFIX_LANE_APPLY + "_" + year + monthStr;
        String tableName_laneKey = ShardTableHandler.TABLE_NAME_PREFIX_LANE_KEY + "_" + year + monthStr;
        String tableName_seatCall = ShardTableHandler.TABLE_NAME_PREFIX_SEAT_CALL + "_" + year + monthStr;
        String tableName_seatImage = ShardTableHandler.TABLE_NAME_PREFIX_SEAT_IMAGE + "_" + year + monthStr;

        shardTableHandler.checkExistTableLaneApply(tableName_laneApply);
        shardTableHandler.checkExistTableLaneKey(tableName_laneKey);
        shardTableHandler.checkExistTableSeatCall(tableName_seatCall);
        shardTableHandler.checkExistTableSeatImage(tableName_seatImage);
    }
}
